home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !preview / c / routines < prev    next >
Encoding:
Text File  |  1990-07-09  |  1.1 KB  |  90 lines

  1. /* c.routines --- auxilary routines.  */
  2.  
  3. #include <stdarg.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include "d2rd.h"
  7. #include "kernel.h"
  8.  
  9. int
  10. fatal (const char *fmt, ...)
  11. {
  12.   va_list ap;
  13.   static struct
  14.    {
  15.      int dummy;
  16.      char msg[2048];
  17.    } msg;
  18.  
  19.   va_start (ap, fmt);
  20.   vsprintf (msg.msg, fmt, ap);
  21.   va_end (ap);
  22.  
  23.   wimp_reporterror ((os_error *) &msg, wimp_EHICANCEL, PROGRAM_NAME);
  24.  
  25.   return (-1);
  26. }
  27.  
  28.  
  29. void
  30. tfatal (const char *fmt, ...)
  31. {
  32.   va_list ap;
  33.   static struct
  34.    {
  35.      int dummy;
  36.      char msg[2048];
  37.    } msg;
  38.  
  39.   va_start (ap, fmt);
  40.   vsprintf (msg.msg, fmt, ap);
  41.   va_end (ap);
  42.  
  43.   wimp_reporterror ((os_error *) &msg, wimp_EHICANCEL, PROGRAM_NAME);
  44.   exit (1);
  45. }
  46.  
  47.  
  48. void *
  49. xmalloc (int i)
  50. {
  51.   void *r = malloc (i ? i : 1);
  52.  
  53.   if (r == NULL)
  54.     {
  55.       tfatal ("Out of VM\n");
  56.       abort ();
  57.     }
  58.   return (r);
  59. }
  60.   
  61.  
  62. void *
  63. xcalloc (int i, int j)
  64. {
  65.   void *r = calloc (i, j);
  66.  
  67.   if (r == NULL)
  68.     {
  69.       tfatal ("Out of VM\n");
  70.       abort ();
  71.     }
  72.   return (r);
  73. }
  74.   
  75.  
  76. void *
  77. xrealloc (void *i, int j)
  78. {
  79.   void *r = realloc (i, j);
  80.  
  81.   if (r == NULL && j != 0)
  82.     {
  83.       tfatal ("Out of VM\n");
  84.       abort ();
  85.     }
  86.   return (r);
  87. }
  88.  
  89. /* EOF */
  90.